<?php

namespace App\Controllers\Member;

use App\Libs\Helper\CommonHelper;
use App\Models\Tag\Tags;
use App\Models\User\User;
use App\Libs\Views\Json;
use App\Models\Member\MemOrder;
use App\Models\Expand\Tixian_log;

/**
        获取提现列表；
 */
class TixianList extends \App\Libs\Base\BaseAction
{
    protected function beforeRun()
    {
        parent::beforeRun();
        $this->needLogin = FALSE;
    }


    public function execute()
    {
        $page = $this->request->getQuery('page','int',1);
        $size = $this->request->getQuery('size','int',10);
        $offset = ($page-1)*$size;
        $matchLog = Tixian_log::findAll([
            '1=1',
            'order' => 'status desc,ctime desc',
            'offset' =>$offset,
            'limit' => $size
        ])->toArray();
        if(empty($matchLog)){
            return Json::view(0,'没有相关记录',[]);
        }

        foreach ($matchLog as $key => $val){
            $uidArray[] = $val['uid'];
        }
        $matchUsers = User::findAll([
            'id in ({ddd:array})',
            'bind' => ['ddd' => $uidArray],
            'columns' => 'id as uid,username,phone,balance,vip'
        ])->toArray();


        $transMatchUser = CommonHelper::setColToKey($matchUsers,'uid');

        foreach ($matchLog as $key => $val){
            if(isset($transMatchUser[$val['uid']])){
//                print_r($transMatchUser[$val['uid']]);die;
                $matchLog[$key] = array_merge($val,$transMatchUser[$val['uid']]);
            }
        }
        return Json::view(0,'ok',$matchLog);
    }
}
